<?php
session_start();
/**
Eventos de FrmRoles
**/

//MApache
require("../../../weblinx/weblinx.php");
//-------

//----Formularios requeridos----

//------------------------------

//----Clases requeridas---------
require("../../Classes/Setter.php");
require("../../Classes/Sentinel.php");
require("../../Classes/Admin/Rol.php");
require("../../Forms/Admin/FrmTableRoles.php");

//-----------------------------

//---Events--------------------
if (isset($_GET['crearRol'])){
	$validator=new ValidatorPHP("","","okValidatorFrmRoles","aceptar",array("onclick"=>"GETMethodSend('okValidatorFrmRoles','tableRoles','../../Events/Admin/EventsFrmRoles.php')"),"cancelValidatorFrmRoles","cancelar",array("onclick"=>"GETMethodSend('cancelValidatorFrmRoles','tableRoles','../../Events/Admin/EventsFrmRoles.php')"));
	$r=0;
	while($r==0){
		if($validator->noEmpty($_GET['nombreRol'],"El campo Nombre no puede estar vacío", "../../../weblinx/Images/warning.png")==false){
			$r++;
			break;
		}
		if($r==0){
			//Verificar que el nombre no esté ya en la bd	
			$sentinel=new Sentinel();
			$idR=$sentinel->idVerify($_GET['nombreRol'],"roles", "nombre");
			if($idR==false){
					$setter=new Setter("../../Config");
					
					$rol=new Rol();
					$rol->setNombre($_GET['nombreRol']);
					$rol->setDescripcion($_GET['descripcionRol']);
					
					$sections=$setter->getSections();
					$sectionesElegidas=array();	
					foreach ($sections as $section){
						if($_GET[$section]=="yes"){
							$sectionesElegidas[]=$section;
						}
					}
					$rol->setSections($sectionesElegidas);
					$rol->guardar();
					
					$messageBox=new MessageBox($image="../../../weblinx/Images/warning.png",$messageText="<b>Se ha creado un nuevo rol con éxito </b>",$okButtonName="okValidatorFrmRoles",$okButtonValue="ok",$okButtonEvents=array("onclick"=>"GETMethodSend('okValidatorFrmRoles','tableRoles','../../Events/Admin/EventsFrmRoles.php')"),$cancelButtonName="cancelValidatorFrmRoles",$cancelButtonValue="cancel",$cancelButtonEvents=array("onclick"=>"GETMethodSend('cancelValidatorFrmRoles','tableRoles','../../Events/Admin/EventsFrmRoles.php')"));
					$messageBox->setVisible("visible");
					$messageBox->show();
				
					$frmTableRoles=new FrmTableRoles();
					$frmTableRoles->show();
					break;
			}
			else{
				$messageBox=new MessageBox($image="../../../weblinx/Images/warning.png",$messageText="<blink><b>Error al tratar de registrar el rol: El nombre ya ha sido registrada antes!! </b></blink>",$okButtonName="okValidatorFrmRoles",$okButtonValue="ok",$okButtonEvents=array("onclick"=>"GETMethodSend('okValidatorFrmRoles','tableRoles','../../Events/Admin/EventsFrmRoles.php')"),$cancelButtonName="cancelValidatorFrmRoles",$cancelButtonValue="cancel",$cancelButtonEvents=array("onclick"=>"GETMethodSend('cancelValidatorFrmRoles','tableRoles','../../Events/Admin/EventsFrmRoles.php')"));
				$messageBox->setVisible("visible");
				$messageBox->show();
				break;
			}
		}
	}	
}
else if(isset($_GET['okValidatorFrmRoles'])){
		$frmTableRoles=new FrmTableRoles();
		$frmTableRoles->show();
}
else if(isset($_GET['cancelValidatorFrmRoles'])){
		$frmTableRoles=new FrmTableRoles();
		$frmTableRoles->show();
}
//-------------

//---Fin Events----------------
?>
